import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.Timestamp;
import java.util.List;
import java.util.Vector;

import com.google.gdata.client.projecthosting.IssuesQuery;
import com.google.gdata.client.projecthosting.ProjectHostingService;
import com.google.gdata.data.HtmlTextConstruct;
import com.google.gdata.data.Person;
import com.google.gdata.data.TextContent;
import com.google.gdata.data.projecthosting.Id;
import com.google.gdata.data.projecthosting.IssueCommentsEntry;
import com.google.gdata.data.projecthosting.IssueCommentsFeed;
import com.google.gdata.data.projecthosting.IssuesEntry;
import com.google.gdata.data.projecthosting.IssuesFeed;
import com.google.gdata.data.projecthosting.Label;
import com.google.gdata.data.projecthosting.MergedInto;

public class merge_dups
{
	

    private String url = "jdbc:mysql://localhost:3306/";
    private String dbName ="lsi_python" ;
    private String driver = "com.mysql.jdbc.Driver";
    private String userName = "root";
    private String password = "123";
    String table = "";
    
	
    public static void main(String args[])	
    {
	
    	String str1= "select * from dupdetails_original";
    	Connection conn = null;
    	Statement stmt = null;
    	//Vector<twoDvector> MainAndDup = new Vector<twoDvector>();
    	Vector<String> mainIssue =  new Vector<String>();
    	Vector<String>dupIssue = new Vector<String>();    	
    db_conn db =  new db_conn();
    conn=db.initdb("lsi_python", "dupdetails", "root", "123");
    try 
      {
		stmt= conn.createStatement();
		stmt.execute(str1);
		ResultSet rs= stmt.getResultSet();
		while(rs.next())
		{
			String main =rs.getString("mainissue");
			String dup  = rs.getString("duplicate");
			//System.out.println("Main="+main+" dup="+dup);
			twoDvector temp =new twoDvector(main,dup);
			//MainAndDup.add(temp);
			mainIssue.add(main);
			dupIssue.add(dup);
	
		}	
		System.out.println("Size="+mainIssue.size()+" dup Size="+dupIssue.size());	
		
		/*for(int i=0;i<MainAndDup.size();i++)
		{
			String dup=MainAndDup.get(i).Duplicate;
			String outerMain = MainAndDup.get(i).MainIssue;
		  for(int j=0;j<MainAndDup.size();j++)
		  {
			 String InnerMain=MainAndDup.get(j).MainIssue;
			 if(dup.equalsIgnoreCase(InnerMain))
			 {
				 MainAndDup.get(j).MainIssue = outerMain;
			 }
			  
		  }//for
		}//for*/
		int count = 0;
		for(int i=0;i<dupIssue.size();i++)
		{
			String dupval = dupIssue.get(i);
			int index = mainIssue.indexOf(dupval);
			while(index!=-1)
			{count++;
		    //mainIssue.removeElementAt(index);		
			mainIssue.set(index, mainIssue.elementAt(i));
			index = mainIssue.indexOf(dupval);
			
				
			}
			
		}
		
		System.out.println("count="+count);
		System.out.println("Size="+mainIssue.size()+" dup Size="+dupIssue.size());
	count =0;	
	for(int i=0;i<mainIssue.size();i++)
		{
			String insert = "insert into dupdetails_modified values('"+ mainIssue.get(i)+"','"+dupIssue.get(i)+"')";
			try{
			stmt.executeUpdate(insert);
			
			}catch(SQLException e)
			{ System.out.println("error..main"+mainIssue.get(i)+"  dup="+dupIssue.get(i)+"  c="+(++count));
			
			}
			
			
		}
		
	  } catch (SQLException e) 
	  {	e.printStackTrace();}
    
	  
	  
	  
    }//main


}//Class
